// jack
function messageBox(str){
    alert(str);
    // new Toast({context:$('body'),message:str}).show();
}
var DEBUG = true;
//跨域web服务调用
function JKjsonP(pobj){
	var pdt = {};
	if (typeof pobj.parameter != "undefined") {
		pdt = pobj.parameter;
	}
	$.ajax({
		   type: "POST",
           url: "http://122.144.131.13:8088/jkstore/"+pobj.ws+"?jsoncallback=?",
		   timeout: 60000,
		   dataType: "jsonp",
		   data: pdt,
		   success: function(rt){
                debugLog(pobj.ws + "-success:");
                debugLog(rt);
		     	var json=eval(rt);
		        if(typeof pobj.sFunc =="function"){
					pobj.sFunc(json,rt);
				}
		   },
		   error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugLog(pobj.ws + "-error");
                debugLog({
                    "XMLHttpRequest": XMLHttpRequest,
                    "textStatus": textStatus,
                    "errorThrown": errorThrown
                });
		        if(typeof pobj.eFunc =="function"){
					pobj.eFunc(XMLHttpRequest, textStatus, errorThrown.message);
				}
		   },
           beforeSend: function() {
                debugLog(pobj.ws + "-beforeSend");
                if (typeof(pobj.beforeSend) == "function") {
                    pobj.beforeSend();
                }
            },
            complete: function() {
                debugLog(pobj.ws + "-complete");
                if (typeof(pobj.complete) == "function") {
                    pobj.complete();
                }
            }
		});
	
}

function JKPprompt(vid,txt,vtime,vth){
	$( vid ).find("p").html(txt).end().popup("open",{ positionTo: "window",transition: "pop",theme: (typeof vth=="undefined")?"b":vth });
	window.setTimeout(function(){$(vid).popup( "close" );},(typeof vtime=="undefined")?2000:vtime);
	}

function JKChangePage(vid,vtr,vchs){
	$.mobile.changePage(vid, { transition: vtr},(typeof vchs=="undefined")?true:vchs );
	}
	function debugLog(str) {
    if (DEBUG) {
        console.log(str);
    }
}
//判断一维数组或对象是否包含指定元素，如果没有返回-1
Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (typeof element == "object") {
            if (this[i].equals(element)) {
                return i;
            }
        } else {
            if (this[i] == element) {
                return i;
            }
        }
    }
    return -1;
};

//去掉字符串首位空格
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//HTML编码
String.prototype.HTMLEnCode = function () {
    return this.replace("'","&#39;").replace("\"","&quot;").replace("<","&lt;").replace(">","&gt;");
}
//HTML解码
String.prototype.HTMLDeCode = function () {
    return this.replace("&#39;","'").replace("&quot;","\"").replace("&lt;","<").replace("&gt;",">");
}

/**
 * 模仿android里面的Toast效果，主要是用于在不打断程序正常执行的情况下显示提示数据
 * @param config
 * @return
 */
var Toast = function(config){
    this.context = config.context==null?$('body'):config.context;//上下文
    this.message = config.message;//显示内容
    this.time = config.time==null?3000:config.time;//持续时间
    this.left = config.left;//距容器左边的距离
    this.top = config.top;//距容器上方的距离
    this.init();
}
var msgEntity;
Toast.prototype = {
    //初始化显示的位置内容等
    init : function(){
        $("#toastMessage").remove();
        //设置消息体
        var msgDIV = new Array();
        msgDIV.push('<div id="toastMessage">');
        msgDIV.push('<span>'+this.message+'</span>');
        msgDIV.push('</div>');
        msgEntity = $(msgDIV.join('')).appendTo(this.context);
        //设置消息样式
        var left = this.left == null ? this.context.width()/2-msgEntity.find('span').width()/2 : this.left;
        var top = this.top == null ? '20px' : this.top;
        msgEntity.css({position:'absolute',top:top,'z-index':'99',left:left,'background-color':'black',color:'white','font-size':'18px',padding:'10px',margin:'10px'});
        msgEntity.hide();
    },
    //显示动画
    show :function(){
        msgEntity.fadeIn(this.time/2);
        msgEntity.fadeOut(this.time/2);
    }
        
}